package collectiontest;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @Author ufo
 * @Description TODO
 * @Date 2021/1/20 15:30
 * @Version 1.0
 */
public class ListTest {

    //Map
    public static void main(String[] args) {
        Map<String, String> a = new ConcurrentHashMap();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                a.put("String.valueOf(i)", UUID.randomUUID().toString().substring(0, 5));
                System.out.println(a);
            }, String.valueOf(i)).start();
        }
    }

    //Set
    public static void main2(String[] args) {
        Set<String> a = new CopyOnWriteArraySet<>();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                a.add(UUID.randomUUID().toString().substring(0, 5));
                System.out.println(a);
            }, String.valueOf(i)).start();
        }
    }

    //List
    public static void main1(String[] args) {
        List<String> a = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                a.add(UUID.randomUUID().toString().substring(0, 5));
                System.out.println(a);
            }, String.valueOf(i)).start();
        }
    }

}
